package com.hzy.friend.controller.front;

import com.hzy.friend.entity.User;
import com.hzy.friend.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 请替换User介绍 controller
*
* @author: 请替换作者
* @version: 1.0
* @datetime: 2019-03-01 17:33:27
*/
@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 保存
     * @param user
     * @return
     */
    @PostMapping(value = "/users")
    public void save(@RequestBody User user) throws Exception{
        userService.save(user);
    }

    /**
     * 修改
     * @param user
     * @return
     */
    @PutMapping(value = "/users")
    public void modify(@RequestBody User user) throws Exception{
        userService.modify(user);
    }

    /**
     * 批量删除
     * @param user
     * @return
     */
    @DeleteMapping(value = "/users")
    public void remove(@RequestBody User user) throws Exception{
        userService.remove(user);
    }

    /**
     * 删除
     * @param userId
     * @return
     */
    @DeleteMapping(value = "/users/{userId}")
    public void remove(@PathVariable String userId) throws Exception{
        userService.remove(userId);
    }

    /**
     * 根据主键查询id
     * @param userId
     * @return
     */
    @GetMapping(value = "/users/{userId}")
    public User findById(@PathVariable String userId) throws Exception{
        return userService.findById(userId);
    }

    /**
     * 查询 -- 不分页
     * @return
     */
    @GetMapping(value = "/users")
    public List<User> find(User user) throws Exception{
        return userService.find(user);
    }
}
